//
//  SHModifyUnionCashCardController.m
//  JiFengDaRen
//
//  Created by SH_iOS on 2017/5/4.
//  Copyright © 2017年 SH_iOS. All rights reserved.
//
#import "BluetoothCell.h"
#import "SHUserCenterHttp.h"
#import "SHBankInfoModel.h"
#import "SHNerAreaList.h"
#import "TDProvince.h"
#import "MiDaiBaoButton.h"
#import "SHAddPayBankCardController.h"
#import "STPickerArea.h"
#import "ZSYPopoverListView.h"
#import "TDBankSearchViewController.h"
#import "SHModifyUnionCashCardController.h"

@interface SHModifyUnionCashCardController ()<UITextFieldDelegate,STPickerAreaDelegate,SHNerAreaListDelegate,ZSYPopoverListDelegate,ZSYPopoverListDatasource>
@property(nonatomic,strong)UILabel *promptLabel;

@property(nonatomic,strong)UIView      *myBgView;
@property(nonatomic,strong)UIView      *firstBgView;
@property(nonatomic,strong)UIView      *secondBgView;
@property(nonatomic,strong)UIView      *thirdBgView;
@property(nonatomic,strong)UIView      *fourthBgView;
@property(nonatomic,strong)UIView      *fiveBgView;
@property(nonatomic,strong)UIView      *sixBgView;

@property(nonatomic,strong)UILabel     *bankCardLabel;
@property(nonatomic,strong)UILabel     *phoneLabel;
@property(nonatomic,strong)UITextField *bankCardTf;
@property(nonatomic,strong)UITextField *phoneTf;
@property(nonatomic,strong)UILabel     *cvvLabel;
@property(nonatomic,strong)UILabel     *expireDateLabel;
@property(nonatomic,strong)UITextField *cvvTf;
@property(nonatomic,strong)UITextField *expireDateTf;
@property(nonatomic,strong)UIButton    *confirmBtn;
@property(nonatomic,strong)NSNumber    *bankCardYype;

@property(nonatomic,strong)UILabel     *bankNameLabel;//银行名称
@property(nonatomic,strong)UILabel     *bankNameButton;

@property(nonatomic,strong)UILabel     *subBankNameLabel;//支行名称
@property(nonatomic,strong)UILabel     *subBankNameButton;


@property(nonatomic,strong)UILabel     *provinceLabel;//省份名称
@property(nonatomic,strong)UILabel     *provinceButton;

@property(nonatomic,strong)UILabel     *cityNameLabel;//城市支行名称
@property(nonatomic,strong)UILabel     *cityNameButton;

@property(nonatomic,strong)NSString     *bankName;
@property(nonatomic,strong)NSString     *subankName;
@property(nonatomic,strong)NSString     *cnaps_code;
@property(nonatomic,strong)NSString     *provinceName;
@property(nonatomic,strong)NSString     *cityName;
@property(nonatomic,strong)NSString     *provinceId;
@property(nonatomic,strong)NSString     *cityId;
@property(nonatomic,strong)NSMutableArray *bankNameListArr;
@property(nonatomic,strong)NSMutableArray *subBankArray;
@property(nonatomic,strong)NSArray *cityListArr;



@end

@implementation SHModifyUnionCashCardController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
    [self layoutUI];
}
- (NSMutableArray *)bankNameListArr{
    if (!_bankNameListArr) {
        _bankNameListArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _bankNameListArr;
}
- (NSMutableArray *)subBankArray{
    if (!_subBankArray) {
        _subBankArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _subBankArray;
}
#pragma mark -- UI布局
-(void)configUI{
    self.view.backgroundColor = KBASEBGCOLOR;
    self.title = @"完善收款卡信息";
    
//    self.myBgView = [[UIView alloc]init];
//    self.myBgView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:self.myBgView];
//    [self.myBgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view.mas_top).with.offset(__I6Height(0));
//        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
//        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
//        make.height.mas_equalTo(__I6Height(20));
//        
//        
//    }];
//    self.bankCardYype = @(12);
//    self.promptLabel = [[UILabel alloc]init];
//    self.promptLabel.text = @"“银联在线”只适用于会员请注册会员后使用";
//    //    @"*目前只支持本人信用卡";
//    self.promptLabel.textColor = KREDCOLOR;
//    self.promptLabel.font = KSystemFont(__I6Width(13));
//    self.promptLabel.textAlignment = NSTextAlignmentLeft;
//    [self.myBgView addSubview:self.promptLabel];
//    [self.promptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.myBgView.mas_left).with.offset(__I6Width(15));
//        make.centerY.mas_equalTo(self.myBgView.mas_centerY);
//        make.right.equalTo(self.myBgView.mas_right).with.offset(__I6Width(-15));
//        make.height.mas_equalTo(__I6Height(20));
//    }];
    //    self.creditBtn = [[MiDaiBaoButton alloc]init];
    //    self.creditBtn.tag = 101;
    //    self.creditBtn.selected = YES;
    //    [self.creditBtn setImage:[UIImage imageNamed:@"midaibao_normal"] forState:UIControlStateNormal];
    //    [self.creditBtn setImage:[UIImage imageNamed:@"midaibao_selected"] forState:UIControlStateSelected];
    //    [self.creditBtn setTitle:@"信用卡" forState:UIControlStateNormal];
    //    [self.creditBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //    self.creditBtn.titleLabel.font = KSystemFont(__I6Width(14));
    //    [self.myBgView addSubview:self.creditBtn];
    //    [self.creditBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.view.mas_left).with.offset(0);
    //        make.centerY.mas_equalTo(self.myBgView.mas_centerY);
    //        make.width.mas_equalTo(KScreenWidth/2);
    //        make.height.mas_equalTo(__I6Height(30));
    //    }];
    
    //    self.debitBtn = [[MiDaiBaoButton alloc]init];
    //    self.debitBtn.tag = 102;
    //    [self.debitBtn setTitle:@"借记卡" forState:UIControlStateNormal];
    //
    //    [self.debitBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //    self.debitBtn.titleLabel.font = KSystemFont(__I6Width(14));
    //    [self.debitBtn setImage:[UIImage imageNamed:@"midaibao_normal"] forState:UIControlStateNormal];
    //    [self.debitBtn setImage:[UIImage imageNamed:@"midaibao_selected"] forState:UIControlStateSelected];
    //    [self.myBgView addSubview:self.debitBtn];
    //    [self.debitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.right.equalTo(self.view.mas_right).with.offset(0);
    //        make.centerY.mas_equalTo(self.myBgView.mas_centerY);
    //        make.width.mas_equalTo(KScreenWidth/2);
    //        make.height.mas_equalTo(__I6Height(30));
    //    }];
    //
    //    [self.debitBtn addTarget:self action:@selector(switchCard:) forControlEvents:UIControlEventTouchUpInside];
    //    [self.creditBtn addTarget:self action:@selector(switchCard:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //=====分割线======//
    self.firstBgView = [[UIView alloc]init];
    self.firstBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.firstBgView];
    
    self.secondBgView = [[UIView alloc]init];
    self.secondBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.secondBgView];
    
    self.thirdBgView = [[UIView alloc]init];
    self.thirdBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.thirdBgView];
    
    self.fourthBgView = [[UIView alloc]init];
    self.fourthBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.fourthBgView];
    
    self.fiveBgView = [[UIView alloc]init];
    self.fiveBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.fiveBgView];
    
    self.sixBgView = [[UIView alloc]init];
    self.sixBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.sixBgView];
    
    
    
    //    self.firstBgView.layer.borderWidth = 0.5;
    //    self.firstBgView.layer.borderColor = KLINECOLOR.CGColor;
    //    self.secondBgView.layer.borderWidth = 0.5;
    //    self.secondBgView.layer.borderColor = KLINECOLOR.CGColor;
    //    self.thirdBgView.layer.borderWidth = 0.5;
    //    self.thirdBgView.layer.borderColor = KLINECOLOR.CGColor;
    //    self.fourthBgView.layer.borderWidth = 0.5;
    //    self.fourthBgView.layer.borderColor = KLINECOLOR.CGColor;
    //    self.fiveBgView.layer.borderWidth = 0.5;
    //    self.fiveBgView.layer.borderColor = KLINECOLOR.CGColor;
    
    //
    
    
    
    
    
    self.bankCardLabel = [[UILabel alloc]init];
    self.bankCardLabel.text = @"银行卡号";
    self.bankCardLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.bankCardLabel.font = KSystemFont(__I6Width(13));
    [self.firstBgView addSubview:self.bankCardLabel];
    
    self.phoneLabel = [[UILabel alloc]init];
    self.phoneLabel.text = @"手机号";
    self.phoneLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.phoneLabel.font = KSystemFont(__I6Width(13));
    [self.secondBgView addSubview:self.phoneLabel];
    
    
    self.bankNameLabel = [[UILabel alloc]init];
    self.bankNameLabel.text = @"银行名称";
    self.bankNameLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.bankNameLabel.font = KSystemFont(__I6Width(13));
    [self.fiveBgView addSubview:self.bankNameLabel];
    
    
    self.subBankNameLabel = [[UILabel alloc]init];
    self.subBankNameLabel.text = @"支行名称";
    self.subBankNameLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.subBankNameLabel.font = KSystemFont(__I6Width(13));
    [self.sixBgView addSubview:self.subBankNameLabel];
    
    
    
    
    self.provinceLabel = [[UILabel alloc]init];
    self.provinceLabel.text = @"银行卡所属省份";
    self.provinceLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.provinceLabel.font = KSystemFont(__I6Width(13));
    [self.thirdBgView addSubview:self.provinceLabel];
    
    self.cityNameLabel = [[UILabel alloc]init];
    self.cityNameLabel.text = @"银行卡所属城市";
    self.cityNameLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.cityNameLabel.font = KSystemFont(__I6Width(13));
    [self.fourthBgView addSubview:self.cityNameLabel];
    
    //    self.phoneLabel = [[UILabel alloc]init];
    //    self.phoneLabel.text = @"手机号";
    //    self.phoneLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    //    self.phoneLabel.font = KSystemFont(__I6Width(13));
    //    [self.secondBgView addSubview:self.phoneLabel];
    //
    
    
    
    //文本框
    self.bankCardTf = [[UITextField alloc]init];
    self.bankCardTf.placeholder = @"请输入银行卡号";
    self.bankCardTf.keyboardType = UIKeyboardTypeNumberPad;
    self.bankCardTf.delegate = self;
    self.bankCardTf.userInteractionEnabled = NO;
    [self.bankCardTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.bankCardTf  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    self.bankCardTf.font = KSystemFont(__I6Width(14));
    self.bankCardTf.textColor = [UIColor blackColor];
    self.bankCardTf.clearButtonMode  = UITextFieldViewModeNever;
    [self.firstBgView addSubview: self.bankCardTf ];
    
    self.phoneTf = [[UITextField alloc]init];
    self.phoneTf.delegate = self;
    self.phoneTf.placeholder = @"请输入预留手机号";
    self.phoneTf.keyboardType = UIKeyboardTypeNumberPad;
    
    self.phoneTf.font = KSystemFont(__I6Width(14));
    self.phoneTf.textColor = [UIColor blackColor];
    [self.phoneTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.phoneTf  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    self.phoneTf.clearButtonMode = UITextFieldViewModeAlways;
    [self.secondBgView addSubview:self.phoneTf ];
    
    
    
    //    self.cvvLabel = [[UILabel alloc]init];
    //    self.cvvLabel.text = @"CVV";
    //    self.cvvLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    //    self.cvvLabel.font = KSystemFont(__I6Width(13));
    //    [self.thirdBgView addSubview:self.cvvLabel];
    //
    //    self.expireDateLabel = [[UILabel alloc]init];
    //    self.expireDateLabel.text = @"有效期";
    //    self.expireDateLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    //    self.expireDateLabel.font = KSystemFont(__I6Width(13));
    //    [self.fourthBgView addSubview:self.expireDateLabel];
    
    
    /*
     //文本框
     self.cvvTf = [[UITextField alloc]init];
     self.cvvTf.placeholder = @"请输入银行卡背面后3位数字";
     self.cvvTf.delegate = self;
     self.cvvTf.keyboardType = UIKeyboardTypeNumberPad;
     
     [self.cvvTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
     [self.cvvTf  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
     self.cvvTf.font = KSystemFont(__I6Width(14));
     self.cvvTf.textColor = [UIColor blackColor];
     self.cvvTf.clearButtonMode  = UITextFieldViewModeAlways;
     [self.thirdBgView addSubview: self.cvvTf ];
     
     self.expireDateTf = [[UITextField alloc]init];
     self.expireDateTf.delegate = self;
     self.expireDateTf.keyboardType = UIKeyboardTypeNumberPad;
     self.expireDateTf.placeholder = @"请输入有效期";
     self.expireDateTf.font = KSystemFont(__I6Width(14));
     self.expireDateTf.textColor = [UIColor blackColor];
     [self.expireDateTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
     [self.expireDateTf  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
     self.expireDateTf.clearButtonMode = UITextFieldViewModeAlways;
     [self.fourthBgView addSubview:self.expireDateTf ];
     
     */
    self.bankNameButton = [[UILabel alloc]init];
    self.bankNameButton.font = KSystemFont(__I6Width(13));
    self.bankNameButton.userInteractionEnabled = YES;
    self.bankNameButton.textColor = [UIColor colorWithHexString:@"#474958"];
    self.bankNameButton.text = @"请选择";
    self.bankNameButton.textAlignment = NSTextAlignmentRight;
    UITapGestureRecognizer *bankTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bankNameButtonClicked:)];
    [self.fiveBgView addGestureRecognizer:bankTap];
    
    [self.fiveBgView addSubview:self.bankNameButton];
    
    
    
    
    self.subBankNameButton = [[UILabel alloc]init];
    self.subBankNameButton.font = KSystemFont(__I6Width(13));
    self.subBankNameButton.userInteractionEnabled = YES;
    self.subBankNameButton.textColor = [UIColor colorWithHexString:@"#474958"];
    self.subBankNameButton.text = @"请选择";
    self.subBankNameButton.textAlignment = NSTextAlignmentRight;
    //[self.subBankNameButton addTarget:self action:@selector(subBankNameButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    UITapGestureRecognizer *subBankTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(subBankNameButtonClicked:)];
    [self.sixBgView addGestureRecognizer:subBankTap];
    [self.sixBgView addSubview:self.subBankNameButton];
    
    
    self.provinceButton = [[UILabel alloc]init];
    self.provinceButton.font = KSystemFont(__I6Width(13));
    self.provinceButton.userInteractionEnabled = YES;
    self.provinceButton.textColor = [UIColor colorWithHexString:@"#474958"];
    self.provinceButton.text = @"请选择";
    self.provinceButton.textAlignment = NSTextAlignmentRight;
    //[self.provinceButton addTarget:self action:@selector(provinceButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    UITapGestureRecognizer *provinceTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(provinceButtonClicked:)];
    [self.thirdBgView addGestureRecognizer:provinceTap];
    
    [self.thirdBgView addSubview:self.provinceButton];
    
    
    self.cityNameButton = [[UILabel alloc]init];
    self.cityNameButton.font = KSystemFont(__I6Width(13));
    self.cityNameButton.userInteractionEnabled = YES;
    self.cityNameButton.textColor = [UIColor colorWithHexString:@"#474958"];
    self.cityNameButton.text = @"请选择";
    self.cityNameButton.textAlignment = NSTextAlignmentRight;
    UITapGestureRecognizer *cityTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cityNameButtonClicked:)];
    [self.fourthBgView addGestureRecognizer:cityTap];
    
    [self.fourthBgView addSubview:self.cityNameButton];
    
    
    
    self.confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.confirmBtn.backgroundColor = KREDCOLOR;
    self.confirmBtn.layer.cornerRadius = __I6Width(8);
    self.confirmBtn.layer.masksToBounds = YES;
    self.confirmBtn.titleLabel.font = KSystemFont(__I6Width(16));
    [self.confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self.confirmBtn setBackgroundImage:[UIImage imageNamed:@"loginHilight"] forState:UIControlStateHighlighted];
    [self.confirmBtn addTarget:self action:@selector(confirmBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.confirmBtn];
    
    
    
    
    
    
    
    
    
}
#pragma mark --- 设置控件位置
-(void)layoutUI{
    //设置约束
    
    
    [self.firstBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(__I6Height(11));
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.secondBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.firstBgView.mas_bottom).with.offset(1);
        
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.thirdBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.secondBgView.mas_bottom).with.offset(1);
        
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.fourthBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.thirdBgView.mas_bottom).with.offset(1);
        
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.fiveBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fourthBgView.mas_bottom).with.offset(1);
        
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    
    [self.sixBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.fiveBgView.mas_bottom).with.offset(1);
    
            make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
            make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
            make.height.mas_equalTo(__I6Height(42));
    
    
       
    }];
    [self.bankCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.firstBgView.mas_centerY);
        make.left.equalTo(self.firstBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    
    
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.secondBgView.mas_centerY);
        make.left.equalTo(self.secondBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.bankNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fiveBgView.mas_centerY);
        make.left.equalTo(self.fiveBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.subBankNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.sixBgView.mas_centerY);
            make.left.equalTo(self.sixBgView.mas_left).with.offset(__I6Width(15));
            make.width.mas_equalTo(__I6Width(55));
            make.height.mas_equalTo(__I6Height(42));
    
    
        
    }];
    [self.provinceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.thirdBgView.mas_centerY);
        make.left.equalTo(self.thirdBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(120));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    [self.cityNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fourthBgView.mas_centerY);
        make.left.equalTo(self.fourthBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(120));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    
    
    
    
    
    [self.bankCardTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.firstBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.bankCardLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.firstBgView.mas_right).with.offset(__I6Width(-15));
        make.height.mas_equalTo(__I6Height(42));
        
    }];
    
    
    [self.phoneTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.secondBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.phoneLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.secondBgView.mas_right).with.offset(__I6Width(-15));
        make.height.mas_equalTo(__I6Height(42));
        
    }];
    
    
    
    
    /*
     [self.cvvLabel mas_makeConstraints:^(MASConstraintMaker *make) {
     make.centerY.equalTo(self.thirdBgView.mas_centerY);
     make.left.equalTo(self.thirdBgView.mas_left).with.offset(__I6Width(15));
     make.width.mas_equalTo(__I6Width(55));
     make.height.mas_equalTo(__I6Height(42));
     
     
     }];
     
     [self.expireDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
     make.centerY.equalTo(self.fourthBgView.mas_centerY);
     make.left.equalTo(self.fourthBgView.mas_left).with.offset(__I6Width(15));
     make.width.mas_equalTo(__I6Width(55));
     make.height.mas_equalTo(__I6Height(42));
     
     
     }];
     
     
     
     [self.cvvTf mas_makeConstraints:^(MASConstraintMaker *make) {
     make.top.equalTo(self.thirdBgView.mas_top).with.offset(__I6Height(0));
     make.left.equalTo(self.cvvLabel.mas_right).with.offset(__I6Width(20));
     make.right.equalTo(self.thirdBgView.mas_right).with.offset(__I6Width(-15));
     make.height.mas_equalTo(__I6Height(42));
     
     }];
     
     
     [self.expireDateTf mas_makeConstraints:^(MASConstraintMaker *make) {
     make.top.equalTo(self.fourthBgView.mas_top).with.offset(__I6Height(0));
     make.left.equalTo(self.expireDateLabel.mas_right).with.offset(__I6Width(20));
     make.right.equalTo(self.fourthBgView.mas_right).with.offset(__I6Width(-15));
     make.height.mas_equalTo(__I6Height(42));
     
     }];
     */
    
    
    [self.bankNameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fiveBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.bankNameLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.fiveBgView.mas_right).with.offset(__I6Width(-30));
        make.height.mas_equalTo(__I6Height(42));
    }];
    
    
    [self.subBankNameButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.sixBgView.mas_top).with.offset(__I6Height(0));
            make.left.equalTo(self.subBankNameLabel.mas_right).with.offset(__I6Width(20));
            make.right.equalTo(self.sixBgView.mas_right).with.offset(__I6Width(-30));
            make.height.mas_equalTo(__I6Height(42));
        }];
    
    
    
    [self.provinceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.thirdBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.provinceLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.thirdBgView.mas_right).with.offset(__I6Width(-30));
        make.height.mas_equalTo(__I6Height(42));
    }];
    [self.cityNameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fourthBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.cityNameLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.fourthBgView.mas_right).with.offset(__I6Width(-30));
        make.height.mas_equalTo(__I6Height(42));
    }];
    
    
    
    
    
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sixBgView.mas_bottom).with.offset(__I6Height(50));
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(__I6Width(326));
        make.height.mas_equalTo(__I6Height(42));
        
    }];
    
    
    UIImageView *arrow1 = [[UIImageView alloc]init];
    arrow1.image = [UIImage imageNamed:@"jmarrow@2x.png"];
    [self.thirdBgView addSubview:arrow1];
    [arrow1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.thirdBgView.mas_centerY);
        make.right.equalTo(self.thirdBgView.mas_right).with.offset(__I6Width(-10));
        make.height.mas_equalTo(__I6Height(14));
        make.width.mas_equalTo(__I6Width(7.5));
    }];
    
    UIImageView *arrow2 = [[UIImageView alloc]init];
    arrow2.image = [UIImage imageNamed:@"jmarrow@2x.png"];
    [self.fourthBgView addSubview:arrow2];
    [arrow2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fourthBgView.mas_centerY);
        make.right.equalTo(self.fourthBgView.mas_right).with.offset(__I6Width(-10));
        make.height.mas_equalTo(__I6Height(14));
        make.width.mas_equalTo(__I6Width(7.5));
    }];
    
    
    UIImageView *arrow3 = [[UIImageView alloc]init];
    arrow3.image = [UIImage imageNamed:@"jmarrow@2x.png"];
    [self.fiveBgView addSubview:arrow3];
    [arrow3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fiveBgView.mas_centerY);
        make.right.equalTo(self.fiveBgView.mas_right).with.offset(__I6Width(-10));
        make.height.mas_equalTo(__I6Height(14));
        make.width.mas_equalTo(__I6Width(7.5));
    }];
    
    
       UIImageView *arrow4 = [[UIImageView alloc]init];
        arrow4.image = [UIImage imageNamed:@"jmarrow@2x.png"];
        [self.sixBgView addSubview:arrow4];
        [arrow4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.sixBgView.mas_centerY);
            make.right.equalTo(self.sixBgView.mas_right).with.offset(__I6Width(-10));
            make.height.mas_equalTo(__I6Height(14));
            make.width.mas_equalTo(__I6Width(7.5));
        }];
    
    self.bankCardTf.text = self.bankCardModel.bank_card_code;

    
}
/*
 -(void)switchCard:(UIButton *)btn{
 
 if (btn.tag == 101 ) {
 self.bankCardYype = @(12);
 self.debitBtn.selected =  NO;
 self.creditBtn.selected = YES;
 [self.myBgView removeFromSuperview];
 [self.firstBgView removeFromSuperview];
 [self.secondBgView removeFromSuperview];
 [self.thirdBgView removeFromSuperview];
 [self.fourthBgView removeFromSuperview];
 [self configUI];
 [self layoutUI];
 }else if(btn.tag == 102 ){
 self.bankCardYype = @(11);
 self.creditBtn.selected = NO;
 self.debitBtn.selected = YES;
 self.thirdBgView.hidden = YES;
 self.fourthBgView.hidden = YES;
 [self.confirmBtn mas_updateConstraints:^(MASConstraintMaker *make)
 {
 make.top.equalTo(self.secondBgView.mas_bottom).with.offset(__I6Height(40));
 make.centerX.mas_equalTo(self.view.mas_centerX);
 make.width.mas_equalTo(__I6Width(325));
 make.height.mas_equalTo(__I6Height(40));
 }];
 
 }
 }
 */

#pragma mark - 选择银行卡名称
- (void)bankNameButtonClicked:(UIButton *)btn{
    [self.view endEditing:YES];
    
    if (self.provinceName.length == 0) {
        [self.view makeToast:@"请选择省份" duration:1.5 position:@"center"];
        return;
    }
    
    if (self.cityName.length == 0) {
        [self.view makeToast:@"请选择城市" duration:1.5 position:@"center"];
        return;
    }
    
    //
    self.subankName = @"";
    self.cnaps_code = @"";
    self.subBankNameButton.text = @"请选择";
    
    [SHUserCenterHttp getBankCnapsCodeBankProId:self.provinceId bankCityId:self.cityId success:^(NSMutableArray *bankInfoArray) {
        if (self.bankNameListArr.count > 0) {
            [self.bankNameListArr removeAllObjects];
        }
        for (SHBankInfoModel *bankInfoModel in bankInfoArray) {
            if (![self.bankNameListArr containsObject:bankInfoModel.bankName]) {
                [self.bankNameListArr addObject:bankInfoModel.bankName];
                
            }
        }

        ZSYPopoverListView *listView = [[ZSYPopoverListView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth - __I6Width(40),KScreenHeight - __I6Height(200))];
        listView.tag = 100;
        listView.titleName.text = @"请选择银行名称";
        listView.datasource = self;
        listView.delegate = self;
        
        [listView show];
    } complection:^(id result) {
        
    } ];

/*
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [TDHttpEngine requestGetBankNameWithCustId:[TDUser defaultUser].custId custMobile:[TDUser defaultUser].custLogin bankProId:self.provinceId  bankCityId:self.cityId  complete:^(BOOL succeed, NSString *msg, NSString *cod, NSArray *bankList) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (succeed) {
            _bankNameListArr = [NSArray arrayWithArray:bankList];
            ZSYPopoverListView *listView = [[ZSYPopoverListView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
            listView.tag = 100;
            listView.titleName.text = @"请选择银行名称";
            listView.datasource = self;
            listView.delegate = self;
            
            [listView show];
            
            
        }else{
            [self.view makeToast:msg duration:2.0f position:@"center"];
        }
        
    }];
    
 */
    
    
}

#pragma mark - 选择支行名称
- (void)subBankNameButtonClicked:(UIButton *)btn{
    
    [self.view endEditing:YES];
    
    if (self.bankName.length == 0) {
        [self.view makeToast:@"请选择银行" duration:2.0f position:@"center"];
        return;
    }
    
    
    [SHUserCenterHttp getBankCnapsCodeBankProId:self.provinceId bankCityId:self.cityId success:^(NSMutableArray *bankInfoArray) {
        
        
        TDBankSearchViewController * search = [[TDBankSearchViewController alloc]initWithNibName:@"TDBankSearchViewController" bundle:[NSBundle bundleWithPath:SRCBUNDLEPATH]];
        search.delegate = self;
        if (self.subBankArray.count > 0) {
            [self.subBankArray removeAllObjects];
        }
        for (int i = 0; i < bankInfoArray.count; i ++) {
            SHBankInfoModel *info = bankInfoArray[i];
            
            if ([info.bankName hasPrefix:_bankName]) {
                
                [self.subBankArray addObject:info];
            }
        }
            
      
        search.dataArray = self.subBankArray.copy;
        [self.navigationController pushViewController:search animated:YES];
        // __weak  typeof(self) weakSelf = self;
        search.PopMyBlock = ^(NSString *branchName, NSString *cnaps_code) {
            
            
            
            self.subankName = branchName;
            self.cnaps_code = cnaps_code;
            self.subBankNameButton.text = branchName;
            
        };
    } complection:^(id result) {
        
    } ];
   /*
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [TDHttpEngine requestGetBankListNameCustId:[TDUser defaultUser].custId custMobile:[TDUser defaultUser].custLogin bankProId:self.provinceId  bankCityId:self.cityId bankName:self.bankName complete:^(BOOL succeed, NSString *msg, NSString *cod, NSArray *bankList) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (succeed) {
            TDBankSearchViewController * search = [[TDBankSearchViewController alloc]initWithNibName:@"TDBankSearchViewController" bundle:[NSBundle bundleWithPath:SRCBUNDLEPATH]];
            search.delegate = self;
            search.dataArray = [NSArray arrayWithArray:bankList];
            [self.navigationController pushViewController:search animated:YES];
            // __weak  typeof(self) weakSelf = self;
            search.PopMyBlock = ^(NSString *branchName, NSString *cnaps_code) {
                
            
                
                self.subankName = branchName;
                self.cnaps_code = cnaps_code;
                self.subBankNameButton.text = branchName;
                
            };
        }else{
            [self.view makeToast:msg duration:2.0f position:@"center"];
        }
    }];
    
    */
    
    
}


#pragma mark -
- (NSInteger)popoverListView:(ZSYPopoverListView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.bankNameListArr.count;
}

- (UITableViewCell *)popoverListView:(ZSYPopoverListView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"identifier";
    BluetoothCell *cell = [tableView dequeueReusablePopoverCellWithIdentifier:identifier];
    if (nil == cell)
    {
        cell = [[BluetoothCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.bluetoothLabel.text = self.bankNameListArr[indexPath.row];
    return cell;
}

- (void)popoverListView:(ZSYPopoverListView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.bankNameListArr.count > 0) {
        self.bankName = self.bankNameListArr[indexPath.row];
        self.bankNameButton.text = self.bankName;
    }
}

#pragma mark - 选择省份名称
- (void)provinceButtonClicked:(UITapGestureRecognizer *)tap{
    if (!self.bankCardTf.text) {
        [self.view makeToast:@"请输入银行卡号" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.phoneTf.text) {
        [self.view makeToast:@"请输入预留手机号" duration:1.5 position:@"center"];
        return;
    }
    self.bankName = @"";
    self.subankName = @"";
    self.cnaps_code = @"";
    self.subBankNameButton.text = @"请选择";
    self.bankNameButton.text = @"请选择";

    
    [self.view endEditing:YES];
    SHNerAreaList *areaList = [[SHNerAreaList alloc]init];
    areaList.delegate = self;
    [areaList show];
    //    STPickerArea *area = [[STPickerArea alloc]init];
    //    area.delegate = self;
    //    [area show];
    
    
}


#pragma mark - 选择城市名称
- (void)cityNameButtonClicked:(UIButton *)btn{
    [self.view endEditing:YES];
    if (!self.bankCardTf.text) {
        [self.view makeToast:@"请输入银行卡号" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.phoneTf.text) {
        [self.view makeToast:@"请输入预留手机号" duration:1.5 position:@"center"];
        return;
    }
    
    SHNerAreaList *areaList = [[SHNerAreaList alloc]init];
    areaList.delegate = self;
    [areaList show];
    
    
}





#pragma mark - 地址选择代理


- (void)pickerArea:(SHNerAreaList *)pickerArea province:(NSString *)province city:(NSString *)city  provinceId:(NSString *)provinceId cityId:(NSString *)cityId  area:(NSString *)area{
    self.provinceButton.text = province;
    self.cityNameButton.text = city;
    self.provinceName = province;
    self.cityName = city;
    self.provinceId = provinceId;
    self.cityId = cityId;
    
    
    
    
    
}


#pragma mark --- 绑定支付的银行卡
- (void)confirmBtnClicked:(UIButton *)btn{
    [self.view endEditing:YES];
    if (self.bankCardTf.text.length == 0) {
        [self.view makeToast:@"请输入银行卡号" duration:1.5 position:@"center"];
        return;
    }else{
        if (![SHHelper checkCardNo:self.bankCardTf.text]) {
            [self.view makeToast:
             @"请输入正确的银行卡号" duration:1.f position:@"center"];
            return;
        }
    }
    
    
    if (self.phoneTf.text.length == 0) {
        [self.view makeToast:@"请输入预留手机号" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.provinceName) {
        [self.view makeToast:@"请选择省份" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.cityName) {
        [self.view makeToast:@"请选择城市" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.bankName) {
        [self.view makeToast:@"请选银行名称" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.subankName) {
            [self.view makeToast:@"请选择支行名称" duration:1.5 position:@"center"];
            return;
        
    }
    //validity_date  和 cvv
//    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
//    [dict setValue:self.bankCardTf.text forKey:@"bank_card_code"];
//    [dict setValue:self.phoneTf.text forKey:@"phone"];
//    [dict setValue:self.provinceName forKey:@"province"];
//    [dict setValue:self.cityName forKey:@"city"];
//    [dict setValue:self.bankName forKey:@"bank_name"];
//    [dict setValue:self.subankName forKey:@"sub_bank_name"];
//    [dict setValue:self.cnaps_code forKey:@"cnaps_code"];
//
//    [dict setValue:@(1) forKey:@"using_choices"];
    
    
    
    //if ([self.bankCardYype isEqual:@(12)]) {
    /*
     if (self.cvvTf.text.length == 0) {
     [self.view makeToast:@"请输入银行卡背面后3位数字" duration:1.5 position:@"center"];
     return;
     }
     if (self.expireDateTf.text.length == 0) {
     [self.view makeToast:@"请输入有效期" duration:1.5 position:@"center"];
     return;
     }
     */
    
    //          params= @{@"bank_card_code":self.bankCardTf.text,@"phone":self.phoneTf.text,@"using_choices":@(2),@"validity_date":self.expireDateTf.text,@"cvv":self.cvvTf.text,@"bank_card_type":@(12)};
    //    params= @{@"bank_card_code":self.bankCardTf.text,@"using_choices":@(2),@"bank_card_type":@(12)};
    //
    //
    //    }else{
    //        params= @{@"bank_card_code":self.bankCardTf.text,@"phone":self.phoneTf.text,@"using_choices":@(2)};
    //    }
    
    //    NSDictionary *params = @{@"bank_card_code":@"6225768769034404",@"phone":@"18074678289",@"using_choices":@(2),@"validity_date":@"0621",@"cvv":@"096",@"bank_card_type":@(12)};
    //
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [SHUserCenterHttp postBankCardInfoWithOrgCardCode:self.bankCardModel.bank_card_code bankCardCode:self.bankCardTf.text bankCardFrontPic:@""  bankCardBackPic:@"" province:self.provinceName city:self.cityName bankName:self.bankName phone:self.phoneTf.text cnapsCode:self.cnaps_code subBankName:self.subankName  bankCardType:11 usingChoices:1 success:^(id result) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5/*延迟执行时间*/ * NSEC_PER_SEC));
        
        dispatch_after(delayTime, dispatch_get_main_queue(), ^{
            
            [self.navigationController popViewControllerAnimated:YES];
            
        });

    } complection:^(id result) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    } failure:^(id erro) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    }];
//
//    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    [MyDataService requestAFURL:[NSString stringWithFormat:KChangeBankCard,self.bankCardModel.bank_card_code] httpMethod:@"PUT" params:dict data:nil complection:^(id result) {
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//        if ([result[@"success"] boolValue]) {
//            [self.view makeToast:@"修改成功" duration:1.5 position:@"center"];
//            dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5/*延迟执行时间*/ * NSEC_PER_SEC));
//            
//            dispatch_after(delayTime, dispatch_get_main_queue(), ^{
//                
//                [self.navigationController popViewControllerAnimated:YES];
//                
//            });
//            
//            
//        }else{
//            [self.view makeToast:result[@"data"] duration:1.5 position:@"center"];
//        }
//        
//        
//        
//    } failure:^(id erro) {
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//
//    }];
    
    
 
    
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
